package com.education.platform.management.controller.user;

import com.education.platform.common.util.BeanUtil;
import com.education.platform.dao.model.ConsumeRecordModel;

import com.education.platform.management.service.UserOrderService;
import com.education.platform.management.vo.request.ConsumeRecordQueryVO;

import com.education.platform.management.vo.response.ConsumeRecordPageInfoVO;
import com.education.platform.management.vo.response.ConsumeRecordResponseVO;
import com.education.platform.management.vo.response.UserOrderResponseVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* describe:
* @author : tomato
* @date: 2020-06-29 10:28:08.867
**/
@RestController
@Api("消费记录")
@RequestMapping("consumeRecord")
@Validated
public class ConsumeRecordController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ConsumeRecordController.class);

	@Autowired
    private UserOrderService userOrderService;

    /**
     * 分页查询
     * @param queryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public ConsumeRecordPageInfoVO selectPageList(@RequestBody @Valid ConsumeRecordQueryVO queryVO) {
        ConsumeRecordModel recordModel = BeanUtil.convert(queryVO, ConsumeRecordModel.class);
        recordModel.setDeleted(false);
        Page<UserOrderResponseVO> page = PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
        List<ConsumeRecordModel> userOrderList = userOrderService.getConsumeList(recordModel);
        ConsumeRecordPageInfoVO recordPageInfoVO = new ConsumeRecordPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), recordPageInfoVO);
        recordPageInfoVO.setPageNum(queryVO.getPageNum());
        List<ConsumeRecordResponseVO> voList = BeanUtil.convert(userOrderList, ConsumeRecordResponseVO.class);
        recordPageInfoVO.setList(voList);
        return recordPageInfoVO;
    }


}
